package cn.xuchunh.campusbbs.utils;

import java.io.File;

/**
 * Created by XuChunH on 2015/10/31.
 */
public class FileUtil {

    public static long getFileSize(File file) {
        if (file == null) {
            return 0;
        }
        if (file.isDirectory()) {
            long size = 0;
            for (File item : file.listFiles()) {
                size += getFileSize(item);
            }
            return size;
        } else {
            return file.length();
        }
    }

    public static boolean deleteFile(File file) {
        if (file == null) {
            return false;
        }
        if (file.isDirectory()) {
            for (File item : file.listFiles()) {
                deleteFile(item);
            }
        }
        return file.delete();
    }

}
